import React from 'react';
import PropTypes from "prop-types";
import eventBus from "../07非父子組件通信EventBus/utils/event-bus";

class Lily extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            chats: []
        }
    }

    chat = function (e) {
        const {chats} = this.state;
        chats.push(e)
        this.setState({
            chats: chats
        })
    };
    render() {
        const {message, call} = this.props;
        const { chats } = this.state;
        return (
            <div>
                Lily, {message},<button onClick={() => call('no')}>say</button>
                <div>chats: {chats.map(e => ',' + e)}</div>
                <div>
                    插槽：{this.props.children}
                </div>
            </div>
        )
    }
    componentDidMount() {
        eventBus.on('chat', e => this.chat(e))
    }
}
Lily.propTypes = {
    children: PropTypes.element
}
export default Lily